#include "FpSPCommunicator.h"

FP_SERIALPORT_BEGIN

FpSPCommunicator::FpSPCommunicator(QObject* parent /*= nullptr*/)
	:QObject(parent)
{

}

FpSPCommunicator::FpSPCommunicator(FpSpCfgData spCfg, QObject *parent)
	: QObject(parent)
{
	_sp.SetSerialPort(spCfg);
}


FpSPCommunicator::~FpSPCommunicator()
{}

bool FpSPCommunicator::SetSerialPortConfig(FpSpCfgData spCfg)
{
	return _sp.SetSerialPort(spCfg);
}

bool FpSPCommunicator::Connect()
{
	if (_sp.isOpen())
	{
		_sp.close();
	}
	if (_sp.open(QIODevice::ReadWrite))
	{
		return true;
	}
	else
	{
		return false;
	}
}

FP_SERIALPORT_END